package com.lyp.crm.service;

import java.util.List;












import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lyp.crm.dao.StudentMapper;
import com.lyp.crm.dao.UserMapper;
import com.lyp.crm.entity.Fenye;
import com.lyp.crm.entity.Student; 
import com.lyp.crm.entity.User;
@Service
public class StudentdaoImp implements Studentdao {
	@Autowired
	private StudentMapper studentMapper;
	
	@Autowired
	private UserMapper userMapper;
	
	
	@Override
	public Fenye<Student> selsctStudent(Fenye<Student> fenye) {
		List<Student> list = studentMapper.selsctStudent(fenye);
		Integer count = studentMapper.selectCount(fenye);
		fenye.setTotal(count);
		fenye.setRows(list);
		return fenye;
	}
	public Fenye<Student> selsctStudent1(Fenye<Student> fenye) {
		List<Student> list = studentMapper.selsctStudent1(fenye);
		Integer count = studentMapper.selectCount1(fenye);
		fenye.setTotal(count);
		fenye.setRows(list);
		return fenye;
	}
	@Override
	public Integer insertStudent(Student student) {
		// TODO Auto-generated method stub
		return studentMapper.insertStudent(student);
	}

	@Override
	public Integer updateStudent(Student student) {
		// TODO Auto-generated method stub
		//����ѯʦ����
		
		
		return studentMapper.updateStudent(student);
	}

	@Override
	public Integer delectStudent(Integer sid) {
		// TODO Auto-generated method stub
		return studentMapper.deleteStudent(sid);
	}

	@Override
	public List<Student> selsctStudentse(Fenye<Student> fenye) {
		List<Student> list = studentMapper.selsctStudent(fenye);
		return list;
	}

	@Override
	public List<Student> selectUserStudent(Integer uid) {
		// TODO Auto-generated method stub
		return studentMapper.selectUserStudent(uid);
	}

	@Override
	public Integer selectUserStudentcount(Integer uid) {
		// TODO Auto-generated method stub
		return studentMapper.selectUserStudentcount(uid);
	}
	@Override
	public Fenye<Student> selsctStudent2(Fenye<Student> fenye) {
		List<Student> list = studentMapper.selsctStudent2(fenye);
		Integer count = studentMapper.selectCount2(fenye);
		fenye.setTotal(count);
		fenye.setRows(list);
		return fenye;
	}
	@SuppressWarnings("null")
	@Override
	//������ѯʦ
	public Integer studentzidongfenpei() {
		Integer updateStudent=0;
		Student student=new Student();
		//��ѯ����ѧ��
		List<Student> list = studentMapper.studentcountscoid();
		System.out.println(list);
		for (int i = 0; i < list.size(); i++) {
			
			Integer sid=list.get(i).getSid();
			student.setSid(list.get(i).getSid());
			student.setScoid(zixunshi());
			Integer update = studentMapper.updateStudent(student);
			if (update>0) {
				updateStudent =updateStudent+1;
			} 
		}
		return updateStudent;
	}
	//��ѯ���ֵ����ѯʦ
	public Integer zixunshi(){
		//��ѯ������ѯʦ
		Integer maxuid=null;
		Integer maxzhi=0;
		Integer shu1=null;
		List<User> zixunshi = userMapper.selectzixunshi();
		//forѭ����ѯѧ����
		for (int i = 0; i < zixunshi.size(); i++) {
			Integer uid=zixunshi.get(i).getUid();
			//��ѯʦȨ��
			Integer ureserved1=zixunshi.get(i).getUreserved1();
			Integer shu = studentMapper.selectcountuid(uid);
				shu=shu-20;
				shu1=(-1*ureserved1);
				shu=shu*shu1;
			if (shu>maxzhi) {
				maxzhi=shu;
				maxuid=uid;
			}
			
		}
		//����һ�����ֵ���ж�������ھ͵������ֵ
		//����һ����ѯʦid���������ֵ�滻
		//����������ѯʦid��
		return maxuid;
		
	}
	@Override
	public Integer updatescause(Student student) {

		
		return studentMapper.updatescause(student);
	}
	@Override
	public Integer updatedeletesid(Integer sid) {
		// TODO Auto-generated method stub
		return studentMapper.updatedeletesid(sid);
	}
}
